<template>
  <a-modal :maskClosable="false"
           :title="title"
           :width="800"
           :visible="visible"
           :confirmLoading="confirmLoading"
           @ok="handleOk"
           @cancel="handleCancel"
           cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" v-bind="layout" :model="model" :rules="validatorRules">
        <a-form-model-item label="医生">
          <a-input :value="model.name+' '+model.doctorType" disabled="disabled" />
        </a-form-model-item>
        <a-form-model-item label="就诊成本价" required prop="registrationFeeCost">
          <a-input-number placeholder="请输入就诊成本价" v-model="model.registrationFeeCost" style="width: 130px"/><label style="margin-left: 10px">元</label>
        </a-form-model-item>
        <a-form-model-item label="就诊销售价" required prop="registrationFeeSale">
          <a-input-number placeholder="请输入就诊销售价" v-model="model.registrationFeeSale" :min="0" style="width: 130px" /><label style="margin-left: 10px">元</label>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, putAction, getAction, postAction } from '@/api/manage'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'

export default {
  name: 'ordCpCategoryModal',
  components: {
    JDictSelectTag
  },
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 }
      },
      confirmLoading: false,
      validatorRules: {
        registrationFeeCost: [{ required: true, message: '请输入就诊成本价!' }],
        registrationFeeSale: [{ required: true, message: '请输入就诊销售价!' }]
      },
      url: {
        edit: '/store/employee/setup/registration/fee'
      }
    }
  },
  created() {
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    close() {
      this.$refs.form.clearValidate()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          postAction(this.url.edit, this.model).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }

  }
}
</script>

<style scoped>

</style>
